Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Also add map_Kd to the OBJ/MTL material kwargs #2332

Merged
merged 1 commit into from
Jan 21, 2025

Conversation

ChuangTseu
Copy link
Contributor

While all the other key/values for the MTL material are provided directly on top of Trimesh's interpretation for SimpleMaterial, then accessible through material.kwargs which is useful for custom handling of the materials, map_Kd isn't. I've had a need for getting the map_Kd file path directly instead of the already loaded PIL.Image.

While all the other key/values for the MTL material are provided directly on top of Trimesh's interpretation for SimpleMaterial, then accessible through material.kwargs which is useful for custom handling of the materials, map_Kd isn't.
I've had a need for getting the map_Kd file path directly instead of the already loaded PIL.Image.
@mikedh
Copy link
Owner

mikedh commented Jan 2, 2025

Thanks for the PR! I guess this would be accessed through: mesh.visual.material.kwargs['file_name']? That seems like it could be a little ambiguous, what if just added it on as a runtime patch value which isn't the greatest but is probably a little clearer:

img = Image.open(util.wrap_as_stream(file_data))
# add the file name on as a runtime attribute
img.file_name = file_name
material["image"] = img

I was also thinking about making a class LazyImage(PIL.Image) which didn't actually load the image until it was accessed, maybe at some point in the future.

@mikedh mikedh changed the base branch from main to refactor/loadtype January 21, 2025 19:42
@mikedh mikedh merged commit 63e06b9 into mikedh:refactor/loadtype Jan 21, 2025
9 checks passed
mikedh added a commit that referenced this pull request Jan 21, 2025
@mikedh
Copy link
Owner

mikedh commented Jan 21, 2025

Actually PIL.Image has a .info dict, I put it there and added a test:
assert m.visual.material.image.info["file_path"].endswith("fuze uv.obj")

Thanks for the PR!

@ChuangTseu
Copy link
Contributor Author

ChuangTseu commented Jan 22, 2025

Was away for a bit, just saw you merged my PR, thank you! To answer your previous question (though not needed anymore) yeah I think it's better to keep the raw "map_kd" key value like it's already done for the other MTL keys, rather than just change the "image".

And thank you for the second change too, I may actually use that one :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants